﻿
CREATE PROCEDURE dbo._CopyObjects
AS SET NOCOUNT ON

SET NOCOUNT ON

DECLARE @Name sysname,@DB sysname
DECLARE cur CURSOR FOR
SELECT Name,DB FROM _Objects WHERE NOT DB IS NULL AND Copy = 1

OPEN cur

FETCH NEXT FROM cur INTO @Name,@DB

BEGIN TRAN

WHILE @@fetch_status = 0 BEGIN
	EXEC _CopyObject @DB,@Name IF @@ERROR <> 0 RETURN
	UPDATE _Objects SET Copy = 0,Date = GETDATE() WHERE Name=@Name AND DB=@DB
	FETCH NEXT FROM cur INTO @Name,@DB
END

COMMIT TRAN
